package com.fau.wmbj.server.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.vladmihalcea.hibernate.type.json.JsonStringType;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.TypeDef;

import javax.persistence.*;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 公司
 *
 * @author jiawei
 * @version 1.0
 * @datetime 2024-03-06 9:08
 */
@Getter
@Setter
@Entity(name = "f_company")
@TypeDef(name = "json", typeClass = JsonStringType.class)
public class Company extends BaseEntity<Long> {

    /**
     * 公司名称
     */
    @Column(name = "name")
    private String name;

    /**
     * 公司描述
     */
    @Column(name = "desc_")
    private String desc_;

    /**
     * 公司地址
     */
    @Column(name = "addr_")
    private String address;

    /**
     * 公司邮箱
     */
    @Column(name = "email")
    private String email;

    /**
     * 公司联系电话
     */
    @Column(name = "phone")
    private String phone;

    /**
     * 再在使用中的模板
     */
    @Column(name = "inuse_template")
    private Long inUseTemplate;

    /**
     * 公司角色
     */
    @JsonIgnore
    @OneToMany(mappedBy = "company", fetch = FetchType.LAZY)
    private List<Role> roles;

    /**
     * 公司客户
     */
    @JsonIgnore
    @OneToMany(mappedBy = "company", fetch = FetchType.LAZY)
    private List<Custom> customs;

    /**
     * 权限
     */
    @JsonIgnore
    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "f_company_menu", joinColumns = @JoinColumn(name = "company_id"), inverseJoinColumns = @JoinColumn(name = "menu_id"))
    @OrderBy(" order asc ")
    private Set<Menu> menus = new HashSet<>();
}
